<?php $this->load->view("partial/header"); 
var_dump($layby);
?>
<style type="text/css">
    #finish_sale_button span {
        background: url("<?php echo base_url(); ?>/images/pieces/complete_sale.png") no-repeat scroll -10px -10px transparent;
        color: #FFFFFF;
        cursor: pointer;
        display: block;
        height: 25px;
        padding-top: 5px;
        text-align: center;
        width: 220px;
        margin-top:10px;
    }
</style>
<?php
if (isset($error_message)) {
    echo '<h1 style="text-align: center;">' . $error_message . '</h1>';
    exit;
}
?>
<div id="receipt_wrapper">
    <table class="tablelist">
<!--        <tr>		
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?>>
        <?php if ($this->config->item('company_logo')) { ?>
                        <div id="company_logo_sale"><?php echo img(array('src' => $this->Appconfig->get_logo_image(), 'width' => 50, 'height' => 50)); ?></div>
        <?php } ?>
                <div id="company_name_sale"><?php echo $this->config->item('company'); ?></div>
            </td>
        </tr>-->
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?> style="text-align:center;">
                <?php echo lang('common_abn') . ": " . $this->config->item('abn'); ?>
            </td>
        </tr>
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?> style="text-align:center;">
                <?php echo ($balance > 0 ? 'Lay by Receipt' : 'Tax Invoice'); ?>
            </td>
        </tr>
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?> style='text-align:right;'>
                <div id="sale_id"><?php echo lang('sales_no') . ": " . $layby_id; ?></div>
                <div><?php echo nl2br($this->config->item('address')); ?></div>
                <div><?php echo lang('common_phone_number') . ": " . $this->config->item('phone'); ?></div>
            </td>
        </tr>
        <?php
        if (isset($customer)) {
            ?>
            <tr>
                <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?>>
                    <div id="receipt_general_info">
                        <div><?php echo lang('customers_customer') . ": " . $customer; ?></div>
                        <?php if ($customer_address != "") { ?>
                            <div><?php echo lang('common_address_1') . ": " . $customer_address . "," . $customer_suburd . "," . $customer_state . "," . $customer_postcode; ?></div>
                        <?php } ?>
                        <?php if ($customer_phone != "") { ?>
                            <div><?php echo lang('common_phone_number') . ": " . $customer_phone; ?></div>
                        <?php } ?>		
                    </div>		
                </td>
            </tr>
            <?php
        }
        ?>		
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?>>
                <div><?php echo lang('employees_staff') . ": " . $employee; ?></div>
                <div style="float: right;"><?php echo lang('employees_date') . ": " . $transaction_time ?></div>			
            </td>		
        </tr>
        <tr>
            <td style="<?php if ($this->config->item('gst')) { ?>width:935px;<?php } else { ?>width:655px;<?php } ?>"><?php echo lang('items_item'); ?></td>
            <td style="width:300px;">Barcode</td>
            <td style="width:20px;"><?php echo lang('common_price'); ?></td>
            <td style="width:5px;text-align:center;"><?php echo lang('sales_quantity'); ?></td>
            <?php if ($this->config->item('gst')) { ?>
                <td style="width:20px;"><?php echo lang('config_gst'); ?></td>
            <?php } ?>
            <td style="width:80px;text-align:right;"><?php echo lang('sales_sub_total'); ?></td>
        </tr>
        <?php
        foreach (array_reverse($cart, true) as $line => $item) {
            ?>
            <tr>
                <td>
                    <div id="receipt_general_info">
                        <div id="item_name"><span><?php echo $item['name']; ?></span><span class='short_name'><?php echo $item['name']; ?></span></div>
                        <?php if ($item['serialnumber'] != "") { ?>
                            <div id="item_serial"><?php echo lang('items_serial') . ": " . $item['serialnumber']; ?></div>
                        <?php } ?>
                        <?php if ($item['description'] != "") { ?>
                            <div id="item_description"><?php echo $item['description']; ?></div>
                        <?php } ?>			
                    </div>
                </td>
                <td><?php echo $item['item_number']; ?></td>
                <?php
                $price = 0;
                if ($item['discount'] < 0) {
                    $price+=($item['price'] - abs($item['discount']));
                } else {
                    $price+=($item['price'] + abs($item['discount']));
                }
                ?>
                <td><div><?php echo to_currency($price); ?></div></td>
                <td style='text-align:center;'><div><?php echo $item['quantity']; ?></div></td>
                <?php if ($this->config->item('gst')) { ?>
                    <td style='text-align:center;'><div><?php echo to_currency($price / 11); ?></div></td>
                <?php } ?>	
                <?php
                $subtotal = 0;
                if ($item['discount'] < 0) {
                    $subtotal+=($item['price'] * $item['quantity'] - abs($item['discount']));
                } else {
                    $subtotal+=($item['price'] * $item['quantity'] + abs($item['discount']));
                }
                ?>
                <td style='text-align:right;'><div><?php if ($this->config->item('gst')) { ?><?php echo to_currency($subtotal + $subtotal / 11); ?><?php } else { ?><?php echo to_currency($subtotal); ?><?php } ?></div></td>
            </tr>

            <?php
        }
        ?>
        <?php if ($this->config->item('gst')) { ?>
            <tr>
                <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="3"<?php } ?> style='text-align:right;'><?php echo lang('config_gst'); ?></td>
                <td colspan="2" style='text-align:right;font-weight: bold;'><div><?php echo to_currency($total / 11); ?></div></td>
            </tr>	
        <?php } ?>
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="3"<?php } ?> style='text-align:right;'><?php if ($this->config->item('gst')) { ?><?php echo lang('sales_total_gst'); ?><?php } else { ?><?php echo lang('sales_total'); ?><?php } ?></td>
            <td colspan="2" style='text-align:right;font-weight: bold;'><div><?php if ($this->config->item('gst')) { ?><?php echo to_currency($total + $total / 11); ?><?php } else { ?><?php echo to_currency($total); ?><?php } ?></div></td>
        </tr>
    </table>
    <table>
        <tr>
            <td colspan="5">
                <div id="finish_sale_button" class="small_button">
                    <span>Print Invoice Again</span> 
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="5" style="height: 200px"></td>
        </tr>
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?>>
                <div><i><?php echo lang('items_term'); ?></i></div>
            </td>
        </tr>
        <tr>
            <td <?php if ($this->config->item('gst')) { ?>colspan="5"<?php } else { ?>colspan="5"<?php } ?> style='text-align:left; width: 80px;'>
                <div>
                    <?php echo nl2br($this->config->item('return_policy')); ?>
                </div>		
            </td>
        </tr>
    </table>
</div>
<?php $this->load->view("partial/footer"); ?>

<?php
if ($this->Appconfig->get('print_after_sale')) {
    ?>
    <script type="text/javascript">
        $(window).load(function()
        {
                
            window.print();
                
            $('#finish_sale_button').click(function(){
                window.print();
                return false;
            });
                
        });
    </script>
    <?php
}
?>